#include "../buffer/BufferManager.hpp"
#include "../buffer/BufferFrame.hpp"

#include <stdlib.h>
#include <stdint.h>
#include <iostream>

using namespace std;

BufferManager* bm;
unsigned pagesOnDisk;
unsigned pagesInRAM;

int main(int argc, char** argv) {
	if (argc==5) {
	  pagesOnDisk = atoi(argv[2]);
	  pagesInRAM = atoi(argv[3]);
	} else {
	  cerr << "usage: " << argv[0] << " <file> <pagesOnDisk> <pagesInRAM> <threads>" << endl;
	  exit(1);
	}

	bm = new BufferManager("Temp3.txt", pagesInRAM);

	for (unsigned j = 0; j < 2; ++j) {
		cout << "Pass "<< j << " starts \n";
		for (unsigned i = 0; i < (pagesOnDisk << 4); ++i) {
			BufferFrame bf = bm->fixPage(i >> 4, false);
			char* data = (char*)bf.getData();
			data[i] = (i>>3)+32;
			cout << "i: " << i << " | "<< bf.size();
			cout << " | " << (char*)bf.getData();
			cout << "\n";
			bm->unfixPage(bf, true);
		}
		cout << "Pass "<< j << " ends \n";
	}

	return 0;
}
